//
//  PersonalCenterController.m
//  steamRoom
//
//  Created by 安建伟 on 2019/7/1.
//  Copyright © 2019 com.thingcom. All rights reserved.
//

#import "PersonalCenterController.h"
#import "PersonalCenterViewCell.h"
#import "UserManagerController.h"

NSString *const CellIdentifier_PersonalCenter = @"CellID_PersonalCenter";
static CGFloat const HEIGHT_CELL = 51.f;
static float HEIGHT_HEADER = 40.f;

@interface PersonalCenterController () <UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) NSString *rssiStr;

@property (nonatomic, strong) UITableView *mineTableView;

@end

@implementation PersonalCenterController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.layer.backgroundColor = [UIColor colorWithRed:246/255.0 green:246/255.0 blue:246/255.0 alpha:1].CGColor;
    
    _mineTableView = [self mineTableView];
    [self setNavItem];
    
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
    [self.rdv_tabBarController setTabBarHidden:NO animated:NO];
    
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    
}

#pragma mark - Lazy load

- (void)setNavItem{
    self.navigationItem.title = LocalString(@"个人中心");
    
}

- (UITableView *)mineTableView{
    if (!_mineTableView) {
        _mineTableView = ({
            UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
            tableView.backgroundColor = [UIColor clearColor];
            tableView.dataSource = self;
            tableView.delegate = self;
            [tableView registerClass:[PersonalCenterViewCell class] forCellReuseIdentifier:CellIdentifier_PersonalCenter];
            tableView.separatorColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.08];
            
            [self.view addSubview:tableView];
            
            tableView.scrollEnabled = NO;
            tableView;
        });
    }
    return _mineTableView;
}

#pragma mark - UITableView Delegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0){
        return 2;
    }else{
        return 1;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    PersonalCenterViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier_PersonalCenter];
    if (cell == nil) {
        cell = [[PersonalCenterViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier_PersonalCenter];
    }
    
    if (indexPath.section == 0){
        if (indexPath.row == 0) {
            cell.leftLabel.text = LocalString(@"设备共享");
            cell.normalImage.image = [UIImage imageNamed:@"img_mine_account"];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            return cell;
        }else{
            cell.leftLabel.text = LocalString(@"意见反馈");
            cell.normalImage.image = [UIImage imageNamed:@"img_mine_houseManage"];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            return cell;
        }
    }else if (indexPath.section == 1){
        
        cell.leftLabel.text = LocalString(@"用户管理");
        cell.normalImage.image = [UIImage imageNamed:@"img_mine_aboutus"];
        cell.rightLabel.text = [GizManage shareInstance].userPhone;
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        return cell;
        
    }else{
        return cell;
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.section == 0){
        if (indexPath.row == 0) {
            
        }else if (indexPath.row == 1){
            
        }
    }else if (indexPath.section == 1){
        UserManagerController *userVC = [[UserManagerController alloc] init];
        [self.navigationController pushViewController:userVC animated:YES];
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return HEIGHT_CELL;
}

//section头部间距

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return HEIGHT_HEADER;//section头部高度
}
//section头部视图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 0)];
    view.backgroundColor = [UIColor clearColor];
    return view ;
}
//section底部间距
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 15;
}
//section底部视图
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 0)];
    view.backgroundColor = [UIColor clearColor];
    return view;
}


@end
